/**
 * 
 */
package org.karthik.ecomm.main;

import java.util.Date;
import org.hibernate.Session;
import org.karthik.ecomm.dto.Employee;
import org.karthik.ecomm.util.HibernateUtil;

/**
 * @author Uday Shankar
 * 
 */
public class EmployeeMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		HibernateUtil util = new HibernateUtil();
		// Instantiate a new employee object which will be persisted
		Employee emp = new Employee();

		// Set the employee attributes
		emp.setEmpID(500);
		emp.setEmpName("Sarang Bijekar");
		emp.setJoinDate(new Date());
		emp.setCity("Nagpur");
		emp.setDescription("Sarang works @ TCS Hyderabad");
		emp.setLargeObject("This should be a large object");

		// Get a session object from the SessionFactory
		Session session = util.getSession();

		// Persist the employee object
		session.beginTransaction();
		session.save(emp);
		session.getTransaction().commit();

		// Closing the session here
		session.close();

		// nullify the emp object
		emp = null;

		// get another session object.remember its using the same SessionFactory
		session = util.getSession();
		session.beginTransaction();
		emp = (Employee) session.get(Employee.class, 500);

		System.out.println("Employee object fetched from DB");
		System.out.println("Employee Name is : " + emp.getEmpName());

	}

}
